﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI.WebControls;

namespace classMeeting.App_Code
{
    public class DataBind
    {
        private int rowCount = 8;  //行数
        public void bindDataView(System.Web.UI.WebControls.DataList data, System.Web.UI.WebControls.PagedDataSource pds, String schoolId, int currentpage)
        {
            DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM classMeeting.dbo.project WHERE submitterSchoolId='" + schoolId + "'ORDER BY [id] DESC");
            pds.AllowPaging = true;
            pds.PageSize = rowCount;
            pds.CurrentPageIndex = currentpage;
            pds.DataSource = dt.Tables[0].DefaultView;
            data.DataSource = pds;
            data.DataSourceID = null;
            data.DataBind();
        }
        public void bindClaDataView(System.Web.UI.WebControls.DataList data, System.Web.UI.WebControls.PagedDataSource pds, String name, int currentpage)
        {
            DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM classMeeting.dbo.project WHERE [hisClassInstructor]='" + name + "' AND [state]='等待班级辅导员审核' ORDER BY [id] DESC");
            pds.AllowPaging = true;
            pds.PageSize = rowCount;
            pds.CurrentPageIndex = currentpage;
            pds.DataSource = dt.Tables[0].DefaultView;
            data.DataSource = pds;
            data.DataSourceID = null;
            data.DataBind();
        }
        public void bindColDataView(System.Web.UI.WebControls.DataList data, System.Web.UI.WebControls.PagedDataSource pds, String name, int currentpage)
        {
            DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM classMeeting.dbo.project WHERE [hisCollegeInstructor]='" + name + "' AND [state]='等待学院负责人审核' ORDER BY [id] DESC");
            pds.AllowPaging = true;
            pds.PageSize = rowCount;
            pds.CurrentPageIndex = currentpage;
            pds.DataSource = dt.Tables[0].DefaultView;
            data.DataSource = pds;
            data.DataSourceID = null;
            data.DataBind();
        }
        public void bindAdmDataView(System.Web.UI.WebControls.DataList data, System.Web.UI.WebControls.PagedDataSource pds, String name, int currentpage)
        {
            DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM classMeeting.dbo.project WHERE [state]='等待学校管理员审核' ORDER BY [id] DESC");
            pds.AllowPaging = true;
            pds.PageSize = rowCount;
            pds.CurrentPageIndex = currentpage;
            pds.DataSource = dt.Tables[0].DefaultView;
            data.DataSource = pds;
            data.DataSourceID = null;
            data.DataBind();
        }
        public void bindDro(DropDownList dro, String college, string position)
        {
            DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM classMeeting.dbo.instructor WHERE [college] ='" + college + "' AND [position] = '" + position + "'");
            dro.DataSource = dt.Tables[0];
            dro.DataSourceID = null;
            dro.DataTextField = dt.Tables[0].Columns["instructor"].ToString();
            dro.DataValueField = dt.Tables[0].Columns["instructor"].ToString();
            dro.DataBind();
            if (!position.Equals("学院负责人"))
            {
                dro.Items.Insert(0, new ListItem("请选择", "请选择"));
                dro.SelectedIndex = 0;
            }
        }
    }

}
